import { createMemoryHistory, createRouter, createWebHashHistory } from 'vue-router'

import Layout from '../components/layout/index.vue'

const routes = [
    { 
      path: '/',
      meta: {
        title: '首页'
      },
      name: 'index',
      component: () => import('./../views/HomeView.vue')
    },
    { 
      path: '/login',
      meta: {
        title: '用户登录'
      },
      name: 'login',
      component: () => import('./../views/login/index.vue')
    },
    {
      path: '/dashboard',
      name: 'dashboard',
      meta: {
        title: '仪表盘',
        icon: 'Odometer',
        isMenu: true,
      },
      component: Layout,
      redirect: '',
      children: [
        {
          path: '',
          meta: {
            title: '仪表盘'
          },
          component: () => import('../../src/views/home/index.vue')
        }
      ]
    },
    {
      path: '/system',
      name: 'system',
      meta: {
        title: '系统管理',
        icon: 'Setting',
        isMenu: true,
      },
      component: Layout,
      children: [
        {
          path: 'users',
          meta: {
            title: '用户管理',
            icon: 'User'
          },
          name: 'usersIndex',
          component: () => import('./../views/admin/users/index.vue')
        },
        {
          path: 'roles',
          meta: {
            title: '角色管理',
            icon: 'Finished'
          },
          name: 'rolesIndex',
          component: () => import('./../views/admin/roles/index.vue')
        }
      ]
    },
    
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
})


router.beforeEach((to, from, next) => {
  if(to.meta && to.meta.title) {
      document.title = to.meta.title
  }
  next()
})

export default router